package goleetcode

func minimumOperations(num string) int {
	n := len(num)
	zero_flag, five_flag := false, false

	for i := n - 1; i >= 0; i-- {
		if num[i] == '0' || num[i] == '5' {
			if zero_flag {
				return n - i - 2
			}
			if num[i] == '0' {
				zero_flag = true
			} else {
				five_flag = true
			}
		} else if num[i] == '2' || num[i] == '7' {
			if five_flag {
				return n -i - 2
			}
		}
	}

	if zero_flag {
		return n - 1
	}

	return n
}